package Dao.impl;

import Dao.BaseDao;
import Dao.MusicBoxesDao;
import Dao.SongRequestDao;
import pojo.SongRequest;

import java.util.List;

public class SongRequestDaoImpl extends BaseDao<SongRequest> implements SongRequestDao {
    MusicBoxesDao musicBoxesDao = new MusicBoxesImpl();
    @Override
    public List<SongRequest> getSongIdByRecipientId(int recipientId) {
        String sql = "select * from SongRequests where recipientId = ?";
        List<SongRequest> songRequestList = getBeanList(sql, recipientId);
        return songRequestList;
    }

    @Override
    public boolean insertSongRequest(SongRequest songRequest) {
        // 在请求表中插入数据
        String sql = "insert into SongRequests(requesterId,songId,recipientId) values(?,?,?)";
        int result2 = update(sql, songRequest.getRequesterId(), songRequest.getSongId(), songRequest.getRecipientId());
        // 在音乐盒子表中插入数据
        boolean result = musicBoxesDao.insertMusicBoxes(songRequest.getRecipientId(), songRequest.getSongId());
        return result;
    }
}
